package com.mapper;

import com.model.EveryDayCon;
import com.model.MessageVo;
import com.model.Openid;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MessagesMapper {

    List<MessageVo> getvopjz1(@Param("tabname") String tabname);

    List<Openid> getopenids();

    int addwxpushlog(MessageVo messageVo);

    Integer issended(MessageVo messageVo);

    List<MessageVo> alexnowdata(@Param("tabname") String tabname);

    List<MessageVo> shitljy(@Param("tabname") String tableName);

    List<MessageVo> shitljyone(@Param("tabname") String tableName);

    Integer handlewechatalarm();

    Integer issendedzx(MessageVo v);

    MessageVo getvozx(@Param("tabname") String tableName);

    List<MessageVo> getvopj2(@Param("tabname") String tabname);

    List<MessageVo> getvoz2(@Param("tabname") String tabname);

    Integer updatevecon(EveryDayCon edc);

    EveryDayCon gettypeid(@Param("id") int id);

    @Select("select stcd from st_stbprp_b")
    @ResultType(String.class)
    List<String> getstcds();

    @Select("SELECT b.stcd stcd,c.stnm stname,a.Voltage voltage, FORMAT(IFNULL(SUM(a.pn05),0) + (SELECT CASE WHEN DATE_FORMAT(b.tm,'%H:%i') <= '08:00' and DATE_FORMAT(NOW(),'%H:%i') > '08:05' THEN 0 ELSE b.pj END), 1) pj, " +
            "a.z z,MAX(a.tm) tm from ${tabname} a, (SELECT stcd, Voltage,pj,pn05,tm from ${tabname} " +
            "WHERE stcd = #{stcd} and pj is not NULL ORDER BY tm desc LIMIT 1) b, st_stbprp_b c " +
            "WHERE a.stcd = c.stcd and a.stcd = #{stcd} and a.tm >= (SELECT CASE WHEN DATE_FORMAT(NOW(),'%H:%i') > '08:05' AND DATE_FORMAT(b.tm,'%H:%i') <= '08:00' " +
            "THEN FROM_UNIXTIME(UNIX_TIMESTAMP(CAST(SYSDATE() AS DATE) + INTERVAL 8 HOUR)) ELSE b.tm END) ORDER BY a.tm DESC;")
    @ResultType(MessageVo.class)
    MessageVo alexnowdata(@Param("tabname") String tabname, @Param("stcd") String stcd);

}
